package homerons;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.net.URL;
import java.util.ArrayList;
import java.io.IOException;
import java.io.DataInputStream;
import javax.swing.*;

import javax.swing.JApplet;




public class test1 extends JApplet  {
	
	public static String[] prefrence =null;
    static Connection conn = null;//DriverManager.getConnection("jdbc:mysql://localhost:3306/students","root","akashdeep");;
	
	
	static Integer no_of_courses = null;
	
	static String temp = null;
	static String[] course_name = new String[10];
	static Integer[] grade = new Integer[10];

	static String name , roll_no =null;
	
	static Integer[] ratings = new Integer[20];
	static String[] ordered_courses = new String[20];
	static String[][] Final_List = new String[6][6];
	
	//public static String[] prefrence = null;// {"SE","IA","DM","FS"};
	
	static String[][] dificulty = {{"SE","8"},{"FS","7"},{"DM","9"},{"FIN","8"},{"IA","6"},{"DHD","7"},{"ML","8"},{"SC","7"},{"DBSI","8"},{"CA","6"},{"LCS","7"},{"RA","6"},{"AC","7"},{"IGDM","8"},{"MCNS","7"},{"ADFT","8"},{"PHY","8"},{"BIOTECH","7"},{"ENTREPRENEURSHIP","6"}};
	static int[] no_of_students = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	static String[] performance = new String[20];//{"SE-10","DM-8"}
	static String[] lst = {"SE", "FS", "DM", "FIN", "IA", "DHD", "ML", "SC", "DBSI", "CA", "LCS", "RA", "AC", "IGDM", "MCNS","ADFT","PHY","BIOTECH","ENTREPRENEURSHIP"};
	
	
	
	
	
	
	
	
	
	JLabel nameLabel = new JLabel("Name");
	JTextField nameValue = new JTextField();
	
	JLabel rollNumber = new JLabel("Roll Number");
	static JTextField rollText = new JTextField();
	
	JCheckBox SEc = new JCheckBox("Software Engineering");
	JCheckBox FSc = new JCheckBox("Foundations of Security");
	JCheckBox DMc = new JCheckBox("Data Mining");
	JCheckBox FINc = new JCheckBox("Introduction to Finance");
	JCheckBox IAc = new JCheckBox("Image Analysis");
	JCheckBox DHDc = new JCheckBox("Digital Hardware Design");
	JCheckBox MLc = new JCheckBox("Machine Learning");
	JCheckBox SCc = new JCheckBox("Secure Coding");
	JCheckBox DBSIc = new JCheckBox("Database Systems Implementation");
	JCheckBox CAc = new JCheckBox("Computer Architecture");
	JCheckBox LCSc = new JCheckBox("Logic For Computer Science");
	JCheckBox RAc = new JCheckBox("Randomized Algorithms");
	JCheckBox ACc = new JCheckBox("Applied Cryptography");
	JCheckBox IGDMc = new JCheckBox("Introduction to GeoSpatial Data Management");
	JCheckBox MCNSc = new JCheckBox("Mobile and Cellular Network Security");
	JCheckBox ADFTYc = new JCheckBox("Application Development For Facebook, Twitter and Youtube");
	JCheckBox PHYc = new JCheckBox("Physics");
	JCheckBox BTc = new JCheckBox("Biotechnology");
	JCheckBox ECc = new JCheckBox("Entrepreneurship as Career");
	
	static JLabel L1 = new JLabel();
	static JLabel L2 = new JLabel();
	static JLabel L3 = new JLabel();
	static JLabel L4 = new JLabel();
	static JLabel R1 = new JLabel();
	static JLabel R2 = new JLabel();
	static JLabel R3 = new JLabel();
	static JLabel R4 = new JLabel();
	
	
	
	
	 public static JFrame f2 = new JFrame("DATA GENERATOR");
     
     public static JPanel JP2 = new JPanel();
     
     public static JCheckBox P1 = new JCheckBox("Advance Programming");
     public static JCheckBox P2 = new JCheckBox("Database Management System");
     public static JCheckBox P3 = new JCheckBox("Digital Circuits");
     public static JCheckBox P4 = new JCheckBox("Probability and Statistics");
     public static JCheckBox P5 = new JCheckBox("Data Structures and Algorithms");
     public static JCheckBox P6 = new JCheckBox("Computer Organization");
     public static JCheckBox P7 = new JCheckBox("Theory of Computation");
     public static JCheckBox P8 = new JCheckBox("Discrete Mathematics");
     public static JCheckBox P9 = new JCheckBox("Computer Networks");
     
     
     public static JLabel nameL = new JLabel("Name :");
     public static JLabel rollL = new JLabel("Roll Number :");
     public static JLabel pc = new JLabel("Previous Course ");
     public static JLabel pc1 = new JLabel("Previous Course ");
     public static JLabel pc3 = new JLabel("Previous Course ");
     public static JLabel grade2 = new JLabel("Grade");
     public static JLabel grade1 = new JLabel("Grade");
     public static JLabel grade3 = new JLabel("Grade");
     
     public static JTextField name1 = new JTextField();
     public static JTextField roll = new JTextField();
     public static JTextField T1 = new JTextField();
     public static JTextField T2 = new JTextField();
     public static JTextField T3 = new JTextField();
     public static JTextField T4 = new JTextField();
     public static JTextField T5 = new JTextField();
     public static JTextField T6 = new JTextField();
     public static JTextField T7 = new JTextField();
     public static JTextField T8 = new JTextField();
     public static JTextField T9 = new JTextField();
     
     public static ArrayList<String> course = new ArrayList<String>();
     public static ArrayList<String> Grade = new ArrayList<String>();
     
     public static JButton JB1 = new JButton("SUBMIT");
	
     JLabel nStudents = new JLabel("");
	
	
	
	
	JFrame f = new JFrame("2ndForm");
	
	
	
	
	
	static JButton add = new JButton("Add");
	static JButton remove = new JButton("Remove");
	static JButton clear = new JButton("Clear");
	JButton Submit = new JButton("Submit");
	static JButton Submit1 = new JButton("Submit");
	static String subject[] = {"Software Engineering", "Foundations of Security", "Data Mining","Introduction to Finance", "Image Analysis", "Digital Hardware Design","Machine Learning", "Secure Coding", "Database Systems Implementation", "Computer Architecture","Logic For Computer Science", "Randomized Algorithms", "Applied Cryptography", "Introduction to GeoSpatial Data Management","Mobile and Cellular Network Security", "Application Development For Facebook, Twitter and Youtube", "Physics", "Biotechnology","Entrepreneurship as Career"};
	
	ArrayList<String> arr = new ArrayList<String>();
	ArrayList<String> Subs = new ArrayList<String>();
	
	JPanel JP = new JPanel();
	DefaultListModel listModel2 = new DefaultListModel();
	
	JList list = new JList(listModel2);
	JScrollPane SP = new JScrollPane(list);
	DefaultListModel listModel = new DefaultListModel();
	JList list1 = new JList(listModel);
	
	
	
	
	
	JLabel team = new JLabel("TEAM : Crusaders");
	JLabel ad = new JLabel("Akashdeep (2009008)");
	JLabel nm = new JLabel("Nikhil Mahajan (2009029)");
	JLabel ps = new JLabel("Prashant Singh (2009033)");

	JButton start = new JButton("START");
	ImageIcon image = new ImageIcon("F:\\CourseVillaPro.jpg");
	JLabel JP3 = new JLabel(image);
	
	
	
	
	public static void final_list() throws SQLException 
	{
		
		
		Statement query,query2 = null;
		ResultSet ans = null;
		ResultSet ans2 = null;
		
		query = conn.createStatement();
		query2 = conn.createStatement();
		ans = query.executeQuery("select * from course_list");
		ans = query.getResultSet();
		
		System.out.println("\n\nPrefrence List");
		for(int j =0; j<prefrence.length; j++)
		{
			System.out.println(prefrence[j]);
		}
		System.out.println("\n\n");
		
		
		
		int i =0;
		while (ans.next()) 
		{
	       
	       String course = ans.getString(2);
	       
	       String pre_req = ans.getString(3);
	       //System.out.println("Course is "+course+"   pre req is "+pre_req );
		
			ratings[i] = 0;
			
			//################# prefrence based###############
			
			
			for(int j =0; j<prefrence.length; j++)
			{
				if(course.equalsIgnoreCase(prefrence[j]))
				{
			
					ratings[i] = ratings[i]+2;
					//System.out.println("prefrence for "+ course + "--- >>> " +ratings[i]);
					break;
				}
			
				
			}
			
			
			
			//################# performance based ############
			
			int flag2 = 0;
			for(int j =0; j<performance.length; j++)
			{
				if(pre_req.equalsIgnoreCase(""))
				{
					ratings[i] = ratings[i] + 1;
					
					break;
				}
				
				if(performance[j] == null)
				{
					continue;
				}
				if(course.equalsIgnoreCase(performance[j].split("-")[0]))
				{
					flag2 = 0;
					
					ratings[i] = ratings[i]+1;
					
					if(Integer.parseInt(performance[j].split("-")[1]) - 6 > 0)
					{
						
						int perf = Integer.parseInt(performance[j].split("-")[1]);
						if (perf==10)
						{
							ratings[i] = ratings[i] + 4;
						}
						
						if (perf==9)
						{
							ratings[i] = ratings[i] + 3;
						}
						
						if (perf==8)
						{
							ratings[i] = ratings[i] + 2;
						}
						
						if (perf==7)
						{
							ratings[i] = ratings[i] + 1;
						}
						
						//ratings[i] = ratings[i] + Integer.parseInt(performance[j].split("-")[1]-6);
					}
					
					//System.out.println("performance for "+ course + "--- >>> " +ratings[i]);
					break;
				}
				else
				{	flag2 = 1;}
				
			}
			if(flag2 == 1)
			{
				ratings[i] = 0;
				System.out.print(course + " ---> ");
				System.out.println(ratings[i]);
				i++;
				continue;

			}
			
			//System.out.println("performance for "+ course + "--- >>> " +ratings[i]);
			
			
			
			
			
			
			//################# difficulty based ############
			
			
			for(int j =0; j<dificulty.length; j++)
			{
				if(course.equalsIgnoreCase(dificulty[j][0]))
				{
					
					int grade = Integer.parseInt(dificulty[j][1]);
					grade = Integer.valueOf(grade).intValue();
					
					
					if(grade == 9)
					{ 
						ratings[i] = ratings[i]+3;
					}
					
					if(grade == 8) 
					{
						ratings[i] = ratings[i]+2;
					}
					
					if(grade == 7) 
					{
						ratings[i] = ratings[i]+1;
					}
					//System.out.println("dificulty for "+ course + "--- >>> " +ratings[i]);
					break;
				}
				
				
			}
			//System.out.println("dificulty for "+ course + "--- >>> " +ratings[i]);
			
			
			System.out.print(course + " ---> ");
			ordered_courses[i]=course;
			System.out.println(ratings[i]);
			i++;
			
			
		}
			
		//System.out.println(ordered_courses[19] + ratings[19]);
		//bubbleSort();
		
		
		int n = ratings.length-1;
		//System.out.println(n);
		int temp = 0;
		String tempo = null;
		
		int min = ratings[0];
		for(int l=0; l < n; l++)
		{
			for(int j=l+1; j < n; j++)
			{
				
					if(ratings[l] < ratings[j])
					{
						//swap the elements!
						temp = ratings[l];
						ratings[l] = ratings[j];
						ratings[j] = temp;
						
						tempo = ordered_courses[l];
						ordered_courses[l] = ordered_courses[j];
						ordered_courses[j] = tempo;
						
						
					}
				
			}
		}
		
		
		
		
		
		System.out.println("\n\n\n<<<<-----FINAL LIST----->>>>\n");
		
		int[] index = new int[8];
		
		for(int j=0;j<8; j++)
		{
			for(int k =0; k<lst.length; k++)
			{
				if(lst[k].equalsIgnoreCase(ordered_courses[j]))
				{
					index[j] = k;
				}
			}
		}
		
		
		for(int k =0;k<8;k++)
		{
			System.out.print(ordered_courses[k] + " ---> ");
			System.out.println(ratings[k]);
			
		}
		
		L1.setText("1. " + subject[index[0]]);
		L2.setText("2. " + subject[index[1]]);
		L3.setText("3. " + subject[index[2]]);
		L4.setText("4. " + subject[index[3]]);
		R1.setText("5. " + subject[index[4]]);
		R2.setText("6. " + subject[index[5]]);
		R3.setText("7. " + subject[index[6]]);
		R4.setText("8. " + subject[index[7]]);
		
		
	}

	
	
	

	
	
	
	
	
	
	
	
	
	

	public static void performance() throws SQLException
	{
		conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/students","root","akashdeep");
		
		Statement query,query2 = null;
		ResultSet ans = null;
		ResultSet ans2 = null;
		
		query = conn.createStatement();
		query2 = conn.createStatement();
		ans = query.executeQuery("select * from course_list");
		ans = query.getResultSet();
		
		
		int k=0;
		
		while (ans.next()) 
		{
	       
	       String columnValue = ans.getString(2);
	       //System.out.println( "course name = " +columnValue);
	       String pr = ans.getString(3);
	       //System.out.println( "pre _ req name = " +pr);
	       
	       if(pr == "")
	       {
	    	   continue;
	       }
	       else
	       {
	    	   //System.out.println("yahan hai problem");
	    	   ans2 = query2.executeQuery("select sem_1 from btech_2009 where roll_no = '" + roll_no + "'");
	    	   ans2 = query2.getResultSet();
	    	   
	    	   while(ans2.next())
	    	   {
	    		   
	    		   String[] temp = ans2.getString("sem_1").split(",");
		    	   
		    	   
		    	   
		    	   for(int i=0;i<temp.length;i++)
		    	   {
		    		   if(temp[i].split("-")[0].equalsIgnoreCase(pr))
		    		   {
		    			   System.out.println(temp[i].split("-")[1]);
		    			      if(temp[i].split("-")[1].equalsIgnoreCase("A+")) {performance[k] = columnValue + "-10";}
		   			       	  if(temp[i].split("-")[1].equalsIgnoreCase("A")) {performance[k] = columnValue + "-10";}
		   			          if(temp[i].split("-")[1].equalsIgnoreCase("A-")) {performance[k] = columnValue + "-9";}
		   			          if(temp[i].split("-")[1].equalsIgnoreCase("B")) {performance[k] = columnValue + "-8";}
		   			          if(temp[i].split("-")[1].equalsIgnoreCase("B-")) {performance[k] = columnValue + "-7";}
		   			          if(temp[i].split("-")[1].equalsIgnoreCase("C")) {performance[k] = columnValue + "-6";}
		   			          if(temp[i].split("-")[1].equalsIgnoreCase("C-")) {performance[k] = columnValue + "-5";}
		   			          if(temp[i].split("-")[1].equalsIgnoreCase("D")) {performance[k] = columnValue + "-4";}
		   			       k++;
		    		   }
		    	   }
	    		   
	    	   }
	    	   
	    	   
	       }
	       
	       
		}
		
		
		
		System.out.println("\nPerformance List");
		for(int i=0; i< performance.length; i++)
		{
			if(performance[i]!=null)
			{
				System.out.println(performance[i]);
			}
			
		}
	    

	}

	
	
	
	
	
	 public void GUI1() throws SQLException{
		 
		 this.setSize(900,400);
		 
         add(JP2);
         JP2.reshape(f2.insets().left, f2.insets().top, 1024, 499);
         JP2.setVisible(true);
         
         JP2.setLayout(null);
         JP2.add(nameL);
         nameL.reshape(f2.insets().left + 370, f2.insets().top + 10, 50, 30);
         nameL.setVisible(true);
         
         JP2.add(name1);
         name1.reshape(f2.insets().left + 470, f2.insets().top + 10, 100, 30);
         name1.setVisible(true);
         name = name1.getText();
         
         JP2.add(rollL);
         rollL.reshape(f2.insets().left + 370, f2.insets().top + 50, 100, 30);
         rollL.setVisible(true);
         
         JP2.add(roll);
         roll.reshape(f2.insets().left + 470, f2.insets().top + 50, 100, 30);
         roll.setVisible(true);
         //roll_no = roll.getText();
         
         JP2.add(pc);
         pc.reshape(f2.insets().left + 60, f2.insets().top + 100, 100, 30);
         pc.setVisible(true);
         
         JP2.add(grade2);
         grade2.reshape(f2.insets().left + 245, f2.insets().top + 100, 100, 30);
         grade2.setVisible(true);
         
         JP2.add(pc1);
         pc1.reshape(f2.insets().left + 370, f2.insets().top + 100, 100, 30);
         pc1.setVisible(true);
         
         JP2.add(grade1);
         grade1.reshape(f2.insets().left + 555, f2.insets().top + 100, 100, 30);
         grade1.setVisible(true);
         
         JP2.add(pc3);
         pc3.reshape(f2.insets().left + 675, f2.insets().top + 100, 100, 30);
         pc3.setVisible(true);
         
         JP2.add(grade3);
         grade3.reshape(f2.insets().left + 835, f2.insets().top + 100, 100, 30);
         grade3.setVisible(true);
 
         JP2.add(P1);
         P1.reshape(f2.insets().left + 30, f2.insets().top + 150, 210, 30);
         P1.setVisible(true);
         
         JP2.add(T1);
         T1.reshape(f2.insets().left + 240, f2.insets().top + 150, 50, 30);
         T1.setVisible(true);
         
         JP2.add(P2);
         P2.reshape(f2.insets().left + 30, f2.insets().top + 200, 210, 30);
         P2.setVisible(true);
         
         JP2.add(T2);
         T2.reshape(f2.insets().left + 240, f2.insets().top + 200, 50, 30);
         T2.setVisible(true);
         
         JP2.add(P3);
         P3.reshape(f2.insets().left + 30, f2.insets().top + 250, 210, 30);
         P3.setVisible(true);
         
         JP2.add(T3);
         T3.reshape(f2.insets().left + 240, f2.insets().top + 250, 50, 30);
         T3.setVisible(true);
         
         JP2.add(P5);
         P5.reshape(f2.insets().left + 340, f2.insets().top + 150, 210, 30);
         P5.setVisible(true);
         
         JP2.add(T5);
         T5.reshape(f2.insets().left + 550, f2.insets().top + 150, 50, 30);
         T5.setVisible(true);
         
         JP2.add(P6);
         P6.reshape(f2.insets().left + 340, f2.insets().top + 200, 210, 30);
         P6.setVisible(true);
         
         JP2.add(T6);
         T6.reshape(f2.insets().left + 550, f2.insets().top + 200, 50, 30);
         T6.setVisible(true);
         
         JP2.add(P7);
         P7.reshape(f2.insets().left + 340, f2.insets().top + 250, 210, 30);
         P7.setVisible(true);
         
         JP2.add(T7);
         T7.reshape(f2.insets().left + 550, f2.insets().top + 250, 50, 30);
         T7.setVisible(true);
         
         JP2.add(P8);
         P8.reshape(f2.insets().left + 650, f2.insets().top + 200, 170, 30);
         P8.setVisible(true);
         
         JP2.add(T8);
         T8.reshape(f2.insets().left + 830, f2.insets().top + 200, 50, 30);
         T8.setVisible(true);
         
         JP2.add(P9);
         P9.reshape(f2.insets().left + 650, f2.insets().top + 250, 170, 30);
         P9.setVisible(true);
         
         JP2.add(T9);
         T9.reshape(f2.insets().left + 830, f2.insets().top + 250, 50, 30);
         T9.setVisible(true);
         
         JP2.add(P4);
         P4.reshape(f2.insets().left + 650, f2.insets().top + 150, 170, 30);
         P4.setVisible(true);
         
         JP2.add(T4);
         T4.reshape(f2.insets().left + 830, f2.insets().top + 150, 50, 30);
         T4.setVisible(true);
         
         
         
         
         JP2.add(JB1);
         JB1.reshape(f2.insets().left + 415, f2.insets().top + 350, 120, 30);
         JB1.setVisible(true);           
         JB1.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e){
                                 
                	 roll_no = roll.getText();
                	 name = name1.getText();
                	 	temp = "";
                	 
                         if(P1.isSelected()){
                                 //course.add("PQ-1");
                                 //Grade.add(T1.getText());
                        	 
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",AP-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "AP-";
                        	 }
                        	 
                        	 temp = temp + T1.getText();
                         }
                         
                         if(P2.isSelected()){
                        	 
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",DBMS-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "DBMS-";
                        	 }
                                
                            	 temp = temp + T2.getText();
                         }
                         if(P3.isSelected()){
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",DC-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "DC-";
                        	 }
                        	 
                        	 temp = temp + T3.getText();
                         }
                         if(P4.isSelected()){
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",PS-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "PS-";
                        	 }
                        	 temp = temp + T4.getText();
                         }
                         if(P5.isSelected()){
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",DSA-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "DSA-";
                        	 }
                        	 
                        	 temp = temp + T5.getText();
                         }
                         if(P6.isSelected()){
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",CO-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "CO-";
                        	 }
                        	 temp = temp + T6.getText();
                         }
                         if(P7.isSelected()){
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",TOC-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "TOC-";
                        	 }
                        	 temp = temp + T7.getText();
                         }
                         if(P8.isSelected()){
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",DM-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "DM-";
                        	 }
                        	 
                        	 temp = temp + T8.getText();
                         }
                         if(P9.isSelected()){
                        	 if(temp != "")
                        	 {
                        		 temp = temp + ",CN-";
                        	 }
                        	 else
                        	 {
                        		 temp = temp + "CN-";
                        	 }
                        	 temp = temp + T9.getText();
                         }
                         
                         System.out.println(temp);
                         
                         
                         
                        Statement query = null;
                 		
                 		ResultSet ans2 = null;
                 		
                 		System.out.println(roll_no + "----" + name + "----" + temp);
                 		
                 		try {
                 			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/students","root","akashdeep");
                 			query = conn.createStatement();
							//query2 = conn.createStatement();
	                 		//ans = query.executeQuery("insert into btech_2009 values (" + roll_no + "," + name + "," + temp + ",'')" );
							int ans = query.executeUpdate("insert into btech_2009 values('" + roll_no + "','" + name + "','" + temp + "',' ')");
	                 		
						} catch (SQLException e1) {
							//System.out.println("errorrrrrrrrrrrrrrr.............");
						}
                 		
                 		
                         
                         
                         
                         
                         for(int i = 0; i < course.size(); i++){
                                 System.out.println(course.get(i)+" = "+Grade.get(i));
                         }
                         
                         JP2.setVisible(false);
                         GUI2();
                 }
         });
 }
	
	
	
	
	
	
	
	
	
	
	public void init() {
	
	setLayout(null);
	this.setSize(1280,800);
	
	
	setBackground(Color.black);
	initializeScreen();
	
	
		
	
			
	}
	
	
	
	
	
	
	public void initializeScreen(){
		add(JP3);
		JP3.reshape(0, 0, 1100, 700);
		JP3.setVisible(true);
		
		add(team);
		team.reshape(1100, 200, 200, 30);
		team.setVisible(true);
		team.setForeground(Color.red);
		team.setFont(new Font("Dialog",1,20));
		
		add(ad);
		ad.reshape(1100, 250, 200, 30);
		ad.setVisible(true);
		ad.setForeground(Color.blue.darker());
		ad.setFont(new Font("Dialog",2,15));
		
		add(nm);
		nm.reshape(1100, 270, 200, 30);
		nm.setVisible(true);
		nm.setForeground(Color.blue.darker());
		nm.setFont(new Font("Dialog",2,15));
		
		add(ps);
		ps.reshape(1100, 290, 200, 30);
		ps.setVisible(true);
		ps.setForeground(Color.blue.darker());
		ps.setFont(new Font("Dialog",2,15));
		
		add(start);
		start.reshape(1130, 340, 100, 30);
		start.setVisible(true);
		start.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e){
				try {
					JP3.setVisible(false);
					GUI1();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}
	
	
	
	
	
	
	
	
	
	
	public void GUI2()
	{	
		this.setSize(800,500);
		add(nameLabel);
		nameLabel.reshape(250,50,100,25);
		
		add(nameValue);
		nameValue.reshape(360,50,100,25);
		//name = nameValue.getText();
		nameValue.setEnabled(false);
		
		add(rollNumber);
		rollNumber.reshape(250,90,100,25);
		
		add(rollText);
		rollText.reshape(360,90,100,25);
		//roll_no = rollText.getText();
		rollText.setEnabled(false);
		
		add(JP);
		JP.reshape(50, 120, 800, 400);
		JP.setLayout(null);
		
		JP.add(SEc);
		SEc.reshape(50, 50, 200, 25);
		
		JP.add(FSc);
		FSc.reshape(50, 80, 200, 25);
		
		JP.add(DMc);
		DMc.reshape(50, 110, 200, 25);
		
		JP.add(FINc);
		FINc.reshape(50, 140, 200, 25);
		
		JP.add(IAc);
		IAc.reshape(50, 170, 200, 25);
		
		JP.add(DHDc);
		DHDc.reshape(50, 200, 200, 25);
		
		JP.add(MLc);
		MLc.reshape(250, 50, 200, 25);
		
		JP.add(SCc);
		SCc.reshape(250, 80, 200, 25);
		
		JP.add(DBSIc);
		DBSIc.reshape(250, 110, 200, 25);
		
		JP.add(CAc);
		CAc.reshape(250, 140, 200, 25);
		
		JP.add(LCSc);
		LCSc.reshape(250, 170, 200, 25);
		
		JP.add(RAc);
		RAc.reshape(250, 200, 200, 25);
		
		JP.add(ACc);
		ACc.reshape(250, 230, 200, 25);
		
		JP.add(IGDMc);
		IGDMc.reshape(450, 50, 200, 25);
		
		JP.add(MCNSc);
		MCNSc.reshape(450, 80, 200, 25);
		
		JP.add(ADFTYc);
		ADFTYc.reshape(450, 110, 200, 25);
		
		JP.add(PHYc);
		PHYc.reshape(450, 140, 200, 25);
		
		JP.add(BTc);
		BTc.reshape(450, 170, 200, 25);
		
		JP.add(ECc);
		ECc.reshape(450, 200, 200, 25);
		
		JP.add(Submit);
		Submit.reshape(270, 280, 100, 25);
		Submit.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e){
				if(SEc.isSelected()){
					Subs.add("SE");
				}
				if(FSc.isSelected()){
					Subs.add("FS");
				}
				if(DMc.isSelected()){
					Subs.add("DM");
				}
				if(FINc.isSelected()){
					Subs.add("FIN");
				}
				if(IAc.isSelected()){
					Subs.add("IA");
				}
				if(DHDc.isSelected()){
					Subs.add("DHD");
				}
				if(MLc.isSelected()){
					Subs.add("ML");
				}
				if(SCc.isSelected()){
					Subs.add("SC");
				}
				if(DBSIc.isSelected()){
					Subs.add("DBSI");
				}
				if(CAc.isSelected()){
					Subs.add("CA");
				}
				if(LCSc.isSelected()){
					Subs.add("LCS");
				}
				if(RAc.isSelected()){
					Subs.add("RA");
				}
				if(ACc.isSelected()){
					Subs.add("AC");
				}
				if(IGDMc.isSelected()){
					Subs.add("IGDM");
				}
				if(MCNSc.isSelected()){
					Subs.add("MCNS");
				}
				if(ADFTYc.isSelected()){
					Subs.add("ADFT");
				}
				if(PHYc.isSelected()){
					Subs.add("PHY");
				}
				if(BTc.isSelected()){
					Subs.add("BIOTECH");
				}
				if(ECc.isSelected()){
					Subs.add("ENTREPRENEURSHIP");
				}
				
				prefrence = new String[Subs.size()];
				
				for(int i = 0; i < Subs.size(); i++){
					prefrence[i]= Subs.get(i);
				}
				/*
				System.out.println(nameValue.getText());
				System.out.println(rollText.getText());
				
				for(int i = 0; i < subjects.length; i++){
					System.out.println(subjects[i]);
				}
				*/
				
				try {
					performance();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				try {
					final_list();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				clear();
				secondForm();
			}
		});

	}
	
	
	
	
	
	public void clear() 
	{ 
	//setLayout(null);
	
	JP.setVisible(false);
	
	nameValue.disable();
	rollText.disable();
	
	Graphics g = this.getGraphics(); 

	Dimension d = this.getSize(); 

	g.fillRect(0,0,d.width,d.height); 

	repaint(); 
	}
	
	public void secondForm()
    {
			this.setSize(870,600);
            //setLayout(null);
            for(int i = 0; i < subject.length; i++){
                    listModel2.add(i, subject[i]);
            }
            
            add(list);
            add(SP);
            
            list.setLocation(120, 300);
            SP.setLocation(120, 300);
            SP.reshape(120, 300, 200, 200);
            SP.getViewport().add(list);
            list.setVisible(true);
            
            this.getContentPane().add(list1);
            list1.reshape(500, 300, 200, 200);
            list1.setVisible(true);
            
            
            
            list.addMouseListener(new MouseListener(){
            	
            	public void mouseClicked(MouseEvent me)
            	{
            		String temporary = null;
            		for(int i =0; i<subject.length;i++)
            		{
            			if(list.getSelectedValue().equals(subject[i]))
            			{
            				
            				try {
								conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/students","root","akashdeep");
								Statement query = conn.createStatement();
								ResultSet ans = query.executeQuery("select no_of_students from course_list where course_name = '" + lst[i] + "'");
							
								while(ans.next())
								{
									temporary = ans.getString("no_of_students");
								}
								
            				
            				} catch (SQLException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
            			}
            		}
            		nStudents.setText(temporary);
            	}

    			@Override
    			public void mouseEntered(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    				
    			}

    			@Override
    			public void mouseExited(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    				
    			}

    			@Override
    			public void mousePressed(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    				
    			}

    			@Override
    			public void mouseReleased(MouseEvent arg0) {
    				// TODO Auto-generated method stub
    				
    			}
            });

                    add(nStudents);
    		nStudents.reshape(390, 280, 50, 30);
    		nStudents.setVisible(true);
            
            
            
            
            add(L1);
            L1.reshape(170, 150, 270, 30);
            L1.setVisible(true);
            
            add(L2);
            L2.reshape(170, 180, 270, 30);
            L2.setVisible(true);
            
            add(L3);
            L3.reshape(170, 210, 270, 30);
            L3.setVisible(true);
            
            add(L4);
            L4.reshape(170, 240, 270, 30);
            L4.setVisible(true);
            
            add(R1);
            R1.reshape(500, 150, 270, 30);
            R1.setVisible(true);
            
            add(R2);
            R2.reshape(500, 180, 270, 30);
            R2.setVisible(true);
            
            add(R3);
            R3.reshape(500, 210, 270, 30);
            R3.setVisible(true);
            
            add(R4);
            R4.reshape(500, 240, 270, 30);
            R4.setVisible(true);
            
            
            add(add);
            add.reshape(360,360,100,25);
            add.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e){
                    if(list.getSelectedIndex() != -1){
                            listModel.addElement(list.getSelectedValue());
                            listModel2.remove(list.getSelectedIndex());
                            list1.show();
                            list.show();
                    }
            }
    });
	
	add(remove);
	remove.reshape(360,400,100,25);
	remove.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e){
			if(list1.getSelectedIndex() != -1){
				listModel2.add(listModel2.size()-1, list1.getSelectedValue());
				listModel.remove(list1.getSelectedIndex());
				list1.setSelectedIndex(list1.getLastVisibleIndex());
			}
			else{
				listModel2.add(listModel2.getSize()-1, listModel.elementAt(listModel.size()-1));
				@SuppressWarnings("deprecation")
				int pos = list1.getLastVisibleIndex();
				if (pos >= 0) {
				    listModel.remove(pos);
				    list1.setSelectedIndex(list1.getLastVisibleIndex());
				}
			}
		}
	});
	
	add(Submit1);
    Submit1.reshape(360,540,100,25);
    Submit1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e){
           
            	for(int i =0; i<listModel.size();i++)
            	{
            		for(int j=0; j<subject.length; j++)
            		{
            			if(listModel.get(i).equals(subject[j]))
            			{
            				try {
								conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/students","root","akashdeep");
								Statement query = conn.createStatement();
								//query2 = conn.createStatement();
		                 		//ans = query.executeQuery("insert into btech_2009 values (" + roll_no + "," + name + "," + temp + ",'')" );
								int ans = query.executeUpdate("update course_list set no_of_students = no_of_students + 1 where course_name = '" + lst[j] + "'");
							
            				
            				} catch (SQLException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
                 			
	     
            			}
            		}
            	}
            	
            	listModel2.clear();
    			for(int i = 0; i < subject.length; i++){
    				listModel2.add(i, subject[i]);
    			}
    				listModel.clear();
    				list1.show();
            	add.setEnabled(false);
            	clear.setEnabled(false);
            	remove.setEnabled(false);
            	
            	
            }
    });
	
	
	add(clear);
	clear.reshape(360,450,100,25);
	clear.addActionListener(new ActionListener() {

		public void actionPerformed(ActionEvent e){
			listModel2.clear();
			for(int i = 0; i < subject.length; i++){
				listModel2.add(i, subject[i]);
			}
				listModel.clear();
				list1.show();
		}
	});

	}
	
	public void main() throws SQLException
	{
		conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/students","root","akashdeep");
		init();
	}

}
